<?php
class Home extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->library ( 'form_validation' );
	}
	
	function index() {
		$this->load->model ( 'Muser' );
		$this->load->helper ( 'form' );
		$this->load->helper ( 'string' );
		
		$this->load->model ( 'Mabout' );
		$data ['uid'] = $this->session->userdata ( 'uid' );
		$data ['cardAboutList'] = $this->Mabout->getAboutListbyClass ( 'C' );
		$data ['aboutList'] = $this->Mabout->getAboutListbyClass ( 'A' );
		
		if ($data ['uid']) {
			$data ['name'] = $this->session->userdata ( 'uname' );
		} else {
			$data ['img'] = $this->getCaptcha ();
			$data ['form1'] = array ('id' => 'loginForm' );
		}
		
		$this->load->model ( 'Mnews' );
		$data ['slider'] = $this->Mnews->getNewsListforShow ();
		$data ['cardPost'] = $this->Mnews->getCardPostList ( 0, 5 );
		$data ['news'] = $this->Mnews->getNewsList ( 0, 5 );
		$data ['activity'] = $this->Mnews->getActivityList ( 0, 9 );
		$data ['actShow'] = $this->Mnews->getShowAct ( 0, 3 );
		
		$this->load->model ( 'Mbusiness' );
		$data ['class1'] = $this->Mbusiness->getClass1ListforHome ();
		$data ['class2'] = $this->Mbusiness->getClass2ListforHome ();
		$data ['region'] = $this->Mbusiness->getRegionListforHome ();
		$data ['area'] = $this->Mbusiness->getAreaListforHome ();
		$data ['business'] = $this->Mbusiness->getBusinessImageListforShow ( 14 );
		
		$this->load->model ( 'Mlink' );
		$data ['link'] = $this->Mlink->getLinkList ( 0,20 );
		
		$data ['form2'] = array ('id' => 'searchForm' );
		$this->load->view ( 'home', $data );
	
	}
	
	// 功能函数
	function logout() {
		$this->session->unset_userdata ( 'uid' );
		$this->session->unset_userdata ( 'uname' );
		redirect ( base_url () . 'home/' );
	}
	
	function getCaptcha() {
		$this->load->helper ( 'captcha' );
		$this->load->helper ( 'string' );
		$vals = array ('word' => random_string ( 'numeric', 5 ), 'img_path' => './captchas/', 'img_url' => base_url () . 'captchas/', 'img_width' => 60, 'img_height' => 30, 'expiration' => 120 );
		$cap = create_captcha ( $vals );
		$this->session->set_userdata ( 'verifyCode', $cap ['word'] );
		return $cap ['image'];
	}

}